package com.iamteer.learnactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class ActivityB extends AppCompatActivity {

    private TextView tv2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);

        tv2 = (TextView) findViewById(R.id.tv2);    //找到文本显示器
        Intent intent = getIntent();                //获取Intent
        Bundle bundle = intent.getExtras();         //获取Bundle

//        tv2.setText(intent.getStringExtra("data")); //获取刚刚传递过来的数据
        tv2.setText(String.format("name: %s\t\tage: %d", bundle.get("name"), bundle.get("age"))); //显示传递过来的数据
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_activity_b, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
